package com.sample.svn;

import android.app.Activity;
import android.content.ContentResolver;
import android.database.Cursor;
import android.os.Bundle;
import android.provider.ContactsContract;
import android.widget.TextView;

public class SampleSVNAndroidActivity extends Activity {
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        TextView tv=new TextView(this);
        //tv.setText(R.string.welcome_msg);
        //setContentView(R.layout.main);
        //setContentView(tv);
        ContentResolver cr=getContentResolver();
        Cursor cur=cr.query(ContactsContract.Contacts.CONTENT_URI, null, null, null, null);
        if(cur.getCount()>0){
        	while(cur.moveToNext()){
        		String id=cur.getString(cur.getColumnIndex(ContactsContract.Contacts._ID));
        		String name=cur.getString(cur.getColumnIndex(ContactsContract.Contacts.DISPLAY_NAME));
        		if(Integer.parseInt(cur.getString(cur.getColumnIndex(ContactsContract.Contacts.HAS_PHONE_NUMBER)))>0){
        			//Phone numbers are stored in their own table
        			//Query phone numbers seperately
        			Cursor pCur=cr.query(ContactsContract.CommonDataKinds.Phone.CONTENT_URI, null, ContactsContract.CommonDataKinds.Phone.CONTACT_ID +" = ?", new String[]{id}, null);
        			while(pCur.moveToNext()){
        				String phone=pCur.getString(pCur.getColumnIndex(ContactsContract.CommonDataKinds.Phone.DATA1));
        				tv.setText(name+" "+phone);
        				setContentView(tv);
        			}
        			pCur.close();
        		}
        	}
        }
    }
}